package cn.fintecher.pangolin.service.manage.request;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.util.Objects;

/**
 * @Auther: xiaqun
 * @Description: 查询敏感词请求参数
 * @Date: 9:40 2019/9/29
 */

@Data
public class FindSensitiveWordRequest {
    @ApiModelProperty(value = "委托方ID")
    private String principalId;

    @ApiModelProperty(value = "提示词")
    private String promptWords;

    @ApiModelProperty(value = "敏感词")
    private String seriousWords;

    public BoolQueryBuilder getBuilder() {
        BoolQueryBuilder builder = new BoolQueryBuilder();
        if (Objects.nonNull(this.principalId)) {
            builder.must(QueryBuilders.matchPhraseQuery("principalId.keyword", this.principalId));
        }
        if (StringUtils.isNotBlank(this.promptWords)) {
            builder.must(QueryBuilders.matchQuery("promptWords.keyword", this.promptWords));
        }
        if (StringUtils.isNotBlank(this.seriousWords)) {
            builder.must(QueryBuilders.matchQuery("seriousWords.keyword", this.seriousWords));
        }
        return builder;
    }
}
